<script>
import global from "@/views/global/global";
import axios from "axios";
export default {
  name: "BookLendingManage",
  data() {
    return {
      realName:global.user.realName,
      //当前时间
      book:{
        borrower: global.user.realName,
        borrowDate: new Date(),
        borrowerDepartment: global.user.departmentName,
        bookId:'',
        approver:global.user.realName,
        bookName:'',
      }
    }
  },
  methods: {
    submitForm(){
      if(this.book.bookId === null || this.book.bookId === undefined || this.book.bookId === ''){
        this.$message({
          type: 'warning',
          message: '图书编号不能为空!'
        });
        return;
      }
      if(this.book.bookName === null || this.book.bookName === ""){
        this.$message({
          type: 'warning',
          message: '图书名称不能为空!'
        });
        return;
      }
      this.$confirm('确定提交吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
      axios.post("/oa/administration/borrowBook",this.book).then((res)=>{
        if(res.data.code === 1){
          this.$message({
            type: 'success',
            message: '借阅成功!'
          });
          this.$router.push('/HomePageView')
        }else {
          this.$message({
            type: 'error',
            message: '借阅失败!'
          });
        }
      })
    }).catch(
          () => {
            this.$message({
              type: 'info',
              message: '已取消'
            });
          }
      )
    },
    cancel(){
      // 返回到我的桌面
      this.$router.push('/HomePageView')
    }
  }
}
</script>

<template>
  <div class="titleBox">
    图书申请管理
  </div>
  <el-form
      label-width="auto"
      :model="book"
      style="max-width: 600px"
  >
    <el-form-item label="借阅人:" >
      <span>{{book.borrower}}</span>
    </el-form-item>
    <el-form-item label="借阅时间:" >
      <el-date-picker disabled
          v-model="book.borrowDate"
          type="datetime"
      />
    </el-form-item>
    <el-form-item label="部门:">
      <span>{{book.borrowerDepartment}}</span>
    </el-form-item>
    <el-form-item label="图书编号:">
      <el-input v-model="book.bookId" placeholder="请输入图书编号"/>
    </el-form-item>
    <el-form-item label="图书名称:">
      <el-input v-model="book.bookName" placeholder="请输入图书名称" />
    </el-form-item>
    <el-form-item label="审批人:">
      <el-select v-model="book.borrower" placeholder="审批人" style="width: 240px">
<!--        默认选中当前用户-->
        <el-option
            :key="this.realName"
            :label="this.realName"
            :value="this.realName"
        />
      </el-select>
    </el-form-item>
    <el-button type="primary" @click="submitForm">提交</el-button>
    <el-button @click="cancel">取消</el-button>
  </el-form>

</template>

<style scoped lang="less">

</style>
